<!-- 模态框组件 -->

<!-- 新增数据源模态框 -->
<div id="addDatasourceModal" class="modal fixed inset-0 bg-black bg-opacity-50 hidden items-center justify-center z-50">
    <div class="modal-content bg-white rounded-xl p-6 w-full max-w-4xl mx-4 max-h-[90vh] overflow-y-auto">
        <div class="flex justify-between items-center mb-6">
            <h3 class="text-xl font-semibold text-slate-800">新增数据源</h3>
            <button onclick="aiAnalysisPage.closeAddDatasourceModal()" class="text-slate-400 hover:text-slate-600">
                <i class="fas fa-times text-xl"></i>
            </button>
        </div>

        <form onsubmit="event.preventDefault(); dataSourceManager.saveDatasource();">
            <!-- 基本信息 -->
            <div class="space-y-4 mb-6">
                <div>
                    <label class="block text-sm font-medium text-slate-700 mb-2">数据源名称 <span class="text-red-500">*</span></label>
                    <input type="text" placeholder="请输入数据源名称" class="w-full px-4 py-2 border border-slate-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
                </div>
                <div>
                    <label class="block text-sm font-medium text-slate-700 mb-2">数据源描述</label>
                    <input type="text" placeholder="请输入数据源描述" class="w-full px-4 py-2 border border-slate-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
                </div>
            </div>

            <!-- 数据源类型选择 -->
            <div class="mb-6">
                <label class="block text-sm font-medium text-slate-700 mb-3">数据源类型 <span class="text-red-500">*</span></label>
                <div class="grid grid-cols-2 gap-4">
                    <div class="datasource-type border-2 border-slate-200 rounded-lg p-4 text-center cursor-pointer" data-type="database">
                        <i class="fas fa-database text-3xl text-indigo-600 mb-2"></i>
                        <p class="font-medium text-slate-800">数据库</p>
                        <p class="text-sm text-slate-500">MySQL、PostgreSQL、Oracle等</p>
                    </div>
                    <div class="datasource-type border-2 border-slate-200 rounded-lg p-4 text-center cursor-pointer" data-type="excel">
                        <i class="fas fa-file-excel text-3xl text-green-600 mb-2"></i>
                        <p class="font-medium text-slate-800">Excel文件</p>
                        <p class="text-sm text-slate-500">支持.xlsx、.xls格式</p>
                    </div>
                </div>
            </div>

            <!-- 数据库配置 -->
            <div id="databaseConfig" class="hidden space-y-4">
                <div class="grid grid-cols-2 gap-4">
                    <div>
                        <label class="block text-sm font-medium text-slate-700 mb-2">数据库类型 <span class="text-red-500">*</span></label>
                        <select id="dbType" class="w-full px-4 py-2 border border-slate-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
                            <option value="mysql">MySQL</option>
                            <option value="postgresql">PostgreSQL</option>
                            <option value="oracle">Oracle</option>
                            <option value="sqlserver">SQL Server</option>
                            <option value="sqlite">SQLite</option>
                        </select>
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-slate-700 mb-2">主机地址 <span class="text-red-500">*</span></label>
                        <input type="text" id="dbHost" placeholder="localhost" class="w-full px-4 py-2 border border-slate-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-slate-700 mb-2">端口 <span class="text-red-500">*</span></label>
                        <input type="number" id="dbPort" placeholder="3306" class="w-full px-4 py-2 border border-slate-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-slate-700 mb-2">数据库名 <span class="text-red-500">*</span></label>
                        <input type="text" id="dbDatabase" placeholder="petition_db" class="w-full px-4 py-2 border border-slate-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-slate-700 mb-2">用户名 <span class="text-red-500">*</span></label>
                        <input type="text" id="dbUsername" placeholder="root" class="w-full px-4 py-2 border border-slate-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-slate-700 mb-2">密码 <span class="text-red-500">*</span></label>
                        <input type="password" id="dbPassword" placeholder="****" class="w-full px-4 py-2 border border-slate-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-slate-700 mb-2">字符集</label>
                        <select id="dbCharset" class="w-full px-4 py-2 border border-slate-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
                            <option value="utf8mb4">utf8mb4</option>
                            <option value="utf8">utf8</option>
                            <option value="gbk">gbk</option>
                            <option value="latin1">latin1</option>
                        </select>
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-slate-700 mb-2">连接超时(秒)</label>
                        <input type="number" id="dbTimeout" placeholder="30" min="1" max="300" class="w-full px-4 py-2 border border-slate-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-slate-700 mb-2">表名</label>
                        <input type="text" id="dbTable" placeholder="petition_data" class="w-full px-4 py-2 border border-slate-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-slate-700 mb-2">模式名</label>
                        <input type="text" id="dbSchema" placeholder="public" class="w-full px-4 py-2 border border-slate-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
                    </div>
                </div>
                
                <!-- 高级配置 -->
                <div class="mt-4 p-4 bg-slate-50 rounded-lg">
                    <div class="flex items-center justify-between mb-3">
                        <h4 class="text-sm font-medium text-slate-700">高级配置</h4>
                        <button type="button" onclick="toggleAdvancedConfig()" class="text-sm text-indigo-600 hover:text-indigo-800">
                            <i id="advancedConfigIcon" class="fas fa-chevron-down mr-1"></i>
                            <span id="advancedConfigText">展开</span>
                        </button>
                    </div>
                    <div id="advancedConfig" class="hidden space-y-4">
                        <div>
                            <label class="block text-sm font-medium text-slate-700 mb-2">SSL模式</label>
                            <select id="dbSslMode" class="w-full px-4 py-2 border border-slate-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
                                <option value="">禁用</option>
                                <option value="prefer">首选</option>
                                <option value="require">必需</option>
                                <option value="verify-ca">验证CA</option>
                                <option value="verify-full">完全验证</option>
                            </select>
                        </div>
                        <div>
                            <label class="block text-sm font-medium text-slate-700 mb-2">连接重试次数</label>
                            <input type="number" id="dbMaxRetry" placeholder="3" min="0" max="10" class="w-full px-4 py-2 border border-slate-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
                        </div>
                    </div>
                </div>
                
                <!-- 操作按钮 -->
                <div class="flex space-x-3">
                    <button type="button" onclick="dataSourceManager.testConnection(this)" class="flex-1 px-4 py-2 border border-indigo-600 text-indigo-600 rounded-lg hover:bg-indigo-50 transition-colors">
                        <i class="fas fa-plug mr-2"></i>测试连接
                    </button>
                    <button type="button" onclick="dataSourceManager.previewEditDatasource()" class="flex-1 px-4 py-2 border border-green-600 text-green-600 rounded-lg hover:bg-green-50 transition-colors">
                        <i class="fas fa-eye mr-2"></i>预览数据
                    </button>
                </div>
            </div>

            <!-- Excel配置 -->
            <div id="excelConfig" class="hidden space-y-4">
                <div>
                    <label class="block text-sm font-medium text-slate-700 mb-2">选择文件</label>
                    <div id="dropZone" class="border-2 border-dashed border-slate-300 rounded-lg p-8 text-center hover:border-indigo-500 transition-colors cursor-pointer relative">
                        <div id="dropZoneContent">
                            <i class="fas fa-cloud-upload-alt text-4xl text-slate-400 mb-4"></i>
                            <p class="text-slate-600 mb-2">点击或拖拽文件到此处上传</p>
                            <p class="text-sm text-slate-500">支持 .xlsx、.xls 格式，最大 10MB</p>
                        </div>
                        <div id="fileInfo" class="hidden">
                            <i class="fas fa-file-excel text-4xl text-green-600 mb-4"></i>
                            <p class="text-slate-600 mb-2" id="fileName"></p>
                            <p class="text-sm text-slate-500" id="fileSize"></p>
                            <button type="button" onclick="dataSourceManager.removeFile()" class="mt-2 text-sm text-red-600 hover:text-red-800">
                                <i class="fas fa-times mr-1"></i>移除文件
                            </button>
                        </div>
                        <div id="uploadProgress" class="hidden">
                            <div class="w-full bg-slate-200 rounded-full h-2 mb-2">
                                <div id="progressBar" class="bg-indigo-600 h-2 rounded-full transition-all duration-300" style="width: 0%"></div>
                            </div>
                            <p class="text-sm text-slate-600" id="progressText">上传中...</p>
                        </div>
                        <input type="file" id="excelFile" accept=".xlsx,.xls,.csv" class="hidden">
                    </div>
                </div>
                
                <!-- 文件预览区域 -->
                <div id="filePreview" class="hidden">
                    <div class="bg-slate-50 rounded-lg p-4">
                        <h4 class="text-sm font-medium text-slate-700 mb-3">文件信息预览</h4>
                        <div id="previewContent" class="space-y-2">
                            <!-- 预览内容将动态填充 -->
                        </div>
                    </div>
                </div>
                
                <div>
                    <label class="block text-sm font-medium text-slate-700 mb-2">工作表名称</label>
                    <select id="sheetName" class="w-full px-4 py-2 border border-slate-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
                        <option value="">选择工作表</option>
                    </select>
                    <input type="text" id="sheetNameCustom" placeholder="或输入自定义工作表名" class="w-full px-4 py-2 border border-slate-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500 mt-2 hidden">
                </div>
                <div class="flex items-center">
                    <input type="checkbox" id="hasHeader" checked class="w-4 h-4 text-indigo-600 border-slate-300 rounded focus:ring-indigo-500">
                    <label for="hasHeader" class="ml-2 text-sm text-slate-700">第一行为标题行</label>
                </div>
                
                <!-- 操作按钮 -->
                <div class="flex space-x-3">
                    <button type="button" onclick="dataSourceManager.testExcelConnection()" class="flex-1 px-4 py-2 border border-indigo-600 text-indigo-600 rounded-lg hover:bg-indigo-50 transition-colors">
                        <i class="fas fa-plug mr-2"></i>测试连接
                    </button>
                    <button type="button" onclick="dataSourceManager.previewExcelData()" class="flex-1 px-4 py-2 border border-green-600 text-green-600 rounded-lg hover:bg-green-50 transition-colors">
                        <i class="fas fa-eye mr-2"></i>预览数据
                    </button>
                </div>
            </div>

            <!-- 提交按钮 -->
            <div class="flex justify-end space-x-3 mt-6 pt-6 border-t border-slate-200">
                <button type="button" onclick="aiAnalysisPage.closeAddDatasourceModal()" class="px-6 py-2 border border-slate-300 text-slate-700 rounded-lg hover:bg-slate-50 transition-colors">
                    取消
                </button>
                <button type="submit" class="px-6 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 transition-colors">
                    <i class="fas fa-save mr-2"></i>保存
                </button>
            </div>
        </form>
    </div>
</div>

<!-- 数据源详情模态框 -->
<div id="datasourceDetailModal" class="modal fixed inset-0 bg-black bg-opacity-50 hidden items-center justify-center z-50">
    <div class="modal-content bg-white rounded-xl p-6 w-full max-w-2xl mx-4">
        <div class="flex justify-between items-center mb-6">
            <h3 class="text-xl font-semibold text-slate-800">数据源详情</h3>
            <button onclick="aiAnalysisPage.closeDatasourceDetailModal()" class="text-slate-400 hover:text-slate-600">
                <i class="fas fa-times text-xl"></i>
            </button>
        </div>

        <div class="space-y-4">
            <div class="grid grid-cols-2 gap-4">
                <div>
                    <span class="text-sm text-slate-600">名称:</span>
                    <p class="font-medium" id="detailName">-</p>
                </div>
                <div>
                    <span class="text-sm text-slate-600">类型:</span>
                    <p class="font-medium" id="detailType">-</p>
                </div>
                <div>
                    <span class="text-sm text-slate-600">状态:</span>
                    <p class="font-medium" id="detailStatus">-</p>
                </div>
                <div>
                    <span class="text-sm text-slate-600">创建时间:</span>
                    <p class="font-medium" id="detailCreated">-</p>
                </div>
            </div>
            
            <div>
                <span class="text-sm text-slate-600">描述:</span>
                <p class="font-medium" id="detailDescription">-</p>
            </div>
            
            <div>
                <span class="text-sm text-slate-600">配置信息:</span>
                <div id="detailConfig" class="mt-2 p-3 bg-slate-50 rounded-lg">
                    <!-- 配置信息将通过JavaScript动态填充 -->
                </div>
            </div>
        </div>

        <div class="flex justify-end space-x-3 mt-6 pt-6 border-t border-slate-200">
            <button onclick="aiAnalysisPage.closeDatasourceDetailModal()" class="px-6 py-2 border border-slate-300 text-slate-700 rounded-lg hover:bg-slate-50 transition-colors">
                关闭
            </button>
            <button class="px-6 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 transition-colors">
                <i class="fas fa-edit mr-2"></i>编辑
            </button>
        </div>
    </div>
</div>

<!-- 数据预览模态框 -->
<div id="dataPreviewModal" class="modal fixed inset-0 bg-black bg-opacity-50 hidden items-center justify-center z-50">
    <div class="modal-content bg-white rounded-xl p-6 w-full max-w-6xl mx-4 max-h-[90vh] overflow-hidden">
        <div class="flex justify-between items-center mb-6">
            <h3 class="text-xl font-semibold text-slate-800">数据预览</h3>
            <div class="flex items-center space-x-2">
                <button onclick="if(window.previewTable) previewTable.exportData('csv')" class="px-3 py-1 text-sm bg-green-100 text-green-700 rounded hover:bg-green-200 transition">
                    <i class="fas fa-download mr-1"></i>导出CSV
                </button>
                <button onclick="if(window.previewTable) previewTable.exportData('json')" class="px-3 py-1 text-sm bg-blue-100 text-blue-700 rounded hover:bg-blue-200 transition">
                    <i class="fas fa-download mr-1"></i>导出JSON
                </button>
                <button onclick="aiAnalysisPage.closeDataPreviewModal()" class="text-slate-400 hover:text-slate-600">
                    <i class="fas fa-times text-xl"></i>
                </button>
            </div>
        </div>

        <!-- 预览数据容器 -->
        <div id="previewDataContainer">
            <!-- 预览数据将通过PreviewTable组件动态渲染 -->
        </div>
    </div>
</div>

<!-- 新建分析任务模态框 -->
<div id="addAnalysisModal" class="modal fixed inset-0 bg-black bg-opacity-50 hidden items-center justify-center z-50">
    <div class="modal-content bg-white rounded-xl p-6 w-full max-w-4xl mx-4 max-h-[90vh] overflow-y-auto">
        <div class="flex justify-between items-center mb-6">
            <h3 class="text-xl font-semibold text-slate-800">新建分析任务</h3>
            <button onclick="analysisManager.closeAddTaskModal()" class="text-slate-400 hover:text-slate-600">
                <i class="fas fa-times text-xl"></i>
            </button>
        </div>

        <form id="addTaskForm" onsubmit="event.preventDefault(); analysisManager.saveTask();">
            <!-- 基本信息 -->
            <div class="space-y-4 mb-6">
                <div>
                    <label class="block text-sm font-medium text-slate-700 mb-2">
                        任务名称 <span class="text-red-500">*</span>
                    </label>
                    <input type="text" id="taskName" required
                           placeholder="请输入任务名称" 
                           class="w-full px-4 py-2 border border-slate-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
                </div>
            </div>

            <!-- 任务配置 -->
            <div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-6">
                <div>
                    <label class="block text-sm font-medium text-slate-700 mb-2">
                        数据源 <span class="text-red-500">*</span>
                    </label>
                    <select id="taskDataSource" required 
                            class="w-full px-4 py-2 border border-slate-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
                        <option value="">请选择数据源</option>
                        <!-- 数据源选项将通过JavaScript动态加载 -->
                    </select>
                </div>
                <div>
                    <label class="block text-sm font-medium text-slate-700 mb-2">
                        执行方式 <span class="text-red-500">*</span>
                    </label>
                    <select id="executionType" required 
                            class="w-full px-4 py-2 border border-slate-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
                        <option value="single_analysis">单次分析</option>
                        <option value="batch_analysis">批量分析</option>
                    </select>
                </div>
                <div>
                    <label class="block text-sm font-medium text-slate-700 mb-2">最大重试次数</label>
                    <input type="number" id="maxRetries" min="0" max="10" value="3"
                           class="w-full px-4 py-2 border border-slate-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
                </div>
            </div>

            <!-- 任务类型选择（多选） -->
            <div class="mb-6">
                <label class="block text-sm font-medium text-slate-700 mb-3">
                    任务类型 <span class="text-red-500">*</span>
                </label>
                <div class="grid grid-cols-2 md:grid-cols-3 gap-3">
                    <div class="flex items-center">
                        <input type="checkbox" id="taskTypeRegional" value="RegionalAnalysis" 
                               class="task-type-checkbox w-4 h-4 text-indigo-600 border-slate-300 rounded focus:ring-indigo-500">
                        <label for="taskTypeRegional" class="ml-2 text-sm text-slate-700">区域分析</label>
                    </div>
                    <div class="flex items-center">
                        <input type="checkbox" id="taskTypeComplaint" value="ComplaintTypeAnalysis" 
                               class="task-type-checkbox w-4 h-4 text-indigo-600 border-slate-300 rounded focus:ring-indigo-500">
                        <label for="taskTypeComplaint" class="ml-2 text-sm text-slate-700">信访类型分析</label>
                    </div>
                    <div class="flex items-center">
                        <input type="checkbox" id="taskTypeSentiment" value="SentimentAnalysis" 
                               class="task-type-checkbox w-4 h-4 text-indigo-600 border-slate-300 rounded focus:ring-indigo-500">
                        <label for="taskTypeSentiment" class="ml-2 text-sm text-slate-700">情感分析</label>
                    </div>
                    <div class="flex items-center">
                        <input type="checkbox" id="taskTypeCompliance" value="ComplianceAnalysis" 
                               class="task-type-checkbox w-4 h-4 text-indigo-600 border-slate-300 rounded focus:ring-indigo-500">
                        <label for="taskTypeCompliance" class="ml-2 text-sm text-slate-700">规范性分析</label>
                    </div>
                    <div class="flex items-center">
                        <input type="checkbox" id="taskTypeDuplicate" value="DuplicateAnalysis" 
                               class="task-type-checkbox w-4 h-4 text-indigo-600 border-slate-300 rounded focus:ring-indigo-500">
                        <label for="taskTypeDuplicate" class="ml-2 text-sm text-slate-700">重复信访分析</label>
                    </div>
                </div>
            </div>

            <!-- 分析时段设置 -->
            <div class="mb-6">
                <label class="block text-sm font-medium text-slate-700 mb-3">分析时段设置</label>
                <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                    <div>
                        <label class="block text-sm text-slate-600 mb-1">开始日期</label>
                        <input type="date" id="analysisStartDate" 
                               class="w-full px-4 py-2 border border-slate-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
                    </div>
                    <div>
                        <label class="block text-sm text-slate-600 mb-1">结束日期</label>
                        <input type="date" id="analysisEndDate" 
                               class="w-full px-4 py-2 border border-slate-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
                    </div>
                </div>
            </div>

  
            <!-- 提交按钮 -->
            <div class="flex justify-end space-x-3 pt-6 border-t border-slate-200">
                <button type="button" onclick="analysisManager.closeAddTaskModal()" 
                        class="px-6 py-2 border border-slate-300 text-slate-700 rounded-lg hover:bg-slate-50 transition-colors">
                    取消
                </button>
                <button type="submit" id="saveTaskBtn"
                        class="px-6 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 transition-colors">
                    <i class="fas fa-save mr-2"></i>创建任务
                </button>
            </div>
        </form>
    </div>
</div>

<!-- 任务详情模态框 -->
<div id="taskDetailModal" class="modal fixed inset-0 bg-black bg-opacity-50 hidden items-center justify-center z-50">
    <div class="modal-content bg-white rounded-xl p-6 w-full max-w-4xl mx-4 max-h-[90vh] overflow-y-auto">
        <div class="flex justify-between items-center mb-6">
            <h3 class="text-xl font-semibold text-slate-800">任务详情</h3>
            <div class="flex items-center space-x-2">
                <button onclick="analysisManager.refreshTaskDetail()" 
                        class="px-3 py-1 text-sm bg-blue-100 text-blue-700 rounded hover:bg-blue-200 transition">
                    <i class="fas fa-sync-alt mr-1"></i>刷新
                </button>
                <button onclick="analysisManager.closeTaskDetailModal()" class="text-slate-400 hover:text-slate-600">
                    <i class="fas fa-times text-xl"></i>
                </button>
            </div>
        </div>

        <!-- 任务基本信息 -->
        <div id="taskDetailContent">
            <!-- 任务详情内容将通过JavaScript动态生成 -->
        </div>
    </div>
</div>

<!-- 编辑任务模态框 -->
<div id="editTaskModal" class="modal fixed inset-0 bg-black bg-opacity-50 hidden items-center justify-center z-50">
    <div class="modal-content bg-white rounded-xl p-6 w-full max-w-4xl mx-4 max-h-[90vh] overflow-y-auto">
        <div class="flex justify-between items-center mb-6">
            <h3 class="text-xl font-semibold text-slate-800">编辑任务</h3>
            <button onclick="analysisManager.closeEditTaskModal()" class="text-slate-400 hover:text-slate-600">
                <i class="fas fa-times text-xl"></i>
            </button>
        </div>

        <form id="editTaskForm" onsubmit="event.preventDefault(); analysisManager.saveEditTask();">
            <!-- 隐藏的任务ID -->
            <input type="hidden" id="editTaskId">

            <!-- 基本信息 -->
            <div class="space-y-4 mb-6">
                <div>
                    <label class="block text-sm font-medium text-slate-700 mb-2">
                        任务名称 <span class="text-red-500">*</span>
                    </label>
                    <input type="text" id="editTaskName" required
                           placeholder="请输入任务名称" 
                           class="w-full px-4 py-2 border border-slate-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
                </div>
            </div>

            <!-- 任务配置 -->
            <div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-6">
                <div>
                    <label class="block text-sm font-medium text-slate-700 mb-2">
                        执行方式 <span class="text-red-500">*</span>
                    </label>
                    <select id="editExecutionType" required 
                            class="w-full px-4 py-2 border border-slate-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
                        <option value="single_analysis">单次分析</option>
                        <option value="batch_analysis">批量分析</option>
                    </select>
                </div>
                <div>
                    <label class="block text-sm font-medium text-slate-700 mb-2">
                        数据源 <span class="text-red-500">*</span>
                    </label>
                    <select id="editDataSource" required 
                            class="w-full px-4 py-2 border border-slate-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
                        <option value="">请选择数据源</option>
                        <!-- 数据源选项将通过JavaScript动态加载 -->
                    </select>
                </div>
                <div>
                    <label class="block text-sm font-medium text-slate-700 mb-2">最大重试次数</label>
                    <input type="number" id="editMaxRetries" min="0" max="10" value="3"
                           class="w-full px-4 py-2 border border-slate-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
                </div>
            </div>

            <!-- 任务类型选择（多选） -->
            <div class="mb-6">
                <div>
                    <label class="block text-sm font-medium text-slate-700 mb-3">
                        任务类型 <span class="text-red-500">*</span>
                    </label>
                    <div class="grid grid-cols-2 md:grid-cols-3 gap-3">
                        <div class="flex items-center">
                            <input type="checkbox" id="editTaskTypeRegional" value="RegionalAnalysis"
                                   class="edit-task-type-checkbox w-4 h-4 text-indigo-600 border-slate-300 rounded focus:ring-indigo-500">
                            <label for="editTaskTypeRegional" class="ml-2 text-sm text-slate-700">区域分析</label>
                        </div>
                        <div class="flex items-center">
                            <input type="checkbox" id="editTaskTypeComplaint" value="ComplaintTypeAnalysis"
                                   class="edit-task-type-checkbox w-4 h-4 text-indigo-600 border-slate-300 rounded focus:ring-indigo-500">
                            <label for="editTaskTypeComplaint" class="ml-2 text-sm text-slate-700">信访类型分析</label>
                        </div>
                        <div class="flex items-center">
                            <input type="checkbox" id="editTaskTypeSentiment" value="SentimentAnalysis"
                                   class="edit-task-type-checkbox w-4 h-4 text-indigo-600 border-slate-300 rounded focus:ring-indigo-500">
                            <label for="editTaskTypeSentiment" class="ml-2 text-sm text-slate-700">情感分析</label>
                        </div>
                        <div class="flex items-center">
                            <input type="checkbox" id="editTaskTypeCompliance" value="ComplianceAnalysis"
                                   class="edit-task-type-checkbox w-4 h-4 text-indigo-600 border-slate-300 rounded focus:ring-indigo-500">
                            <label for="editTaskTypeCompliance" class="ml-2 text-sm text-slate-700">规范性分析</label>
                        </div>
                        <div class="flex items-center">
                            <input type="checkbox" id="editTaskTypeDuplicate" value="DuplicateAnalysis"
                                   class="edit-task-type-checkbox w-4 h-4 text-indigo-600 border-slate-300 rounded focus:ring-indigo-500">
                            <label for="editTaskTypeDuplicate" class="ml-2 text-sm text-slate-700">重复信访分析</label>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 分析时段设置 -->
            <div class="mb-6">
                <label class="block text-sm font-medium text-slate-700 mb-3">分析时段设置</label>
                <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                    <div>
                        <label class="block text-sm text-slate-600 mb-1">开始日期</label>
                        <input type="date" id="editAnalysisStartDate" 
                               class="w-full px-4 py-2 border border-slate-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
                    </div>
                    <div>
                        <label class="block text-sm text-slate-600 mb-1">结束日期</label>
                        <input type="date" id="editAnalysisEndDate" 
                               class="w-full px-4 py-2 border border-slate-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
                    </div>
                </div>
            </div>

    
            <!-- 提交按钮 -->
            <div class="flex justify-end space-x-3 pt-6 border-t border-slate-200">
                <button type="button" onclick="analysisManager.closeEditTaskModal()" 
                        class="px-6 py-2 border border-slate-300 text-slate-700 rounded-lg hover:bg-slate-50 transition-colors">
                    取消
                </button>
                <button type="submit" id="saveEditTaskBtn"
                        class="px-6 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 transition-colors">
                    <i class="fas fa-save mr-2"></i>保存修改
                </button>
            </div>
        </form>
    </div>
</div>

<div id="addServiceModal" class="modal fixed inset-0 bg-black bg-opacity-50 hidden items-center justify-center z-50">
    <!-- 服务管理模态框内容 -->
</div>

<!-- 全局JavaScript函数 -->
<script>
    // 切换高级配置显示
    function toggleAdvancedConfig() {
        const config = document.getElementById('advancedConfig');
        const icon = document.getElementById('advancedConfigIcon');
        const text = document.getElementById('advancedConfigText');
        
        if (config.classList.contains('hidden')) {
            config.classList.remove('hidden');
            icon.className = 'fas fa-chevron-up mr-1';
            text.textContent = '收起';
        } else {
            config.classList.add('hidden');
            icon.className = 'fas fa-chevron-down mr-1';
            text.textContent = '展开';
        }
    }
    
    // 显示任务详情（占位函数）
    function showTaskDetail(taskId) {
        console.log('显示任务详情:', taskId);
        // TODO: 实现任务详情显示逻辑
    }
    
    // 初始化文件上传功能（在模态框显示时调用）
    function initializeFileUpload() {
        const dropZone = document.getElementById('dropZone');
        const fileInput = document.getElementById('excelFile');
        
        if (!dropZone || !fileInput) return;
        
        // 防止重复绑定事件
        if (dropZone.dataset.uploadInitialized) return;
        
        // 标记为已初始化
        dropZone.dataset.uploadInitialized = 'true';
        
        // 点击上传
        dropZone.addEventListener('click', (e) => {
            // 检查点击的元素是否是按钮或按钮的子元素
            if (e.target.tagName !== 'BUTTON' && !e.target.closest('button')) {
                // 确保文件输入元素存在
                const fileInput = document.getElementById('excelFile');
                if (fileInput) {
                    fileInput.click();
                }
            }
        });
        
        // 文件选择
        fileInput.addEventListener('change', (e) => {
            if (e.target.files.length > 0) {
                dataSourceManager.handleFileSelect(e.target.files[0]);
            }
        });
        
        // 拖拽功能
        dropZone.addEventListener('dragover', (e) => {
            e.preventDefault();
            dropZone.classList.add('border-indigo-500', 'bg-indigo-50');
        });
        
        dropZone.addEventListener('dragleave', (e) => {
            e.preventDefault();
            dropZone.classList.remove('border-indigo-500', 'bg-indigo-50');
        });
        
        dropZone.addEventListener('drop', (e) => {
            e.preventDefault();
            dropZone.classList.remove('border-indigo-500', 'bg-indigo-50');
            
            const files = e.dataTransfer.files;
            if (files.length > 0) {
                dataSourceManager.handleFileSelect(files[0]);
            }
        });
        
        // 工作表选择变化
        const sheetSelect = document.getElementById('sheetName');
        const sheetCustom = document.getElementById('sheetNameCustom');
        
        if (sheetSelect && sheetCustom) {
            sheetSelect.addEventListener('change', (e) => {
                if (e.target.value === '__custom__') {
                    sheetSelect.classList.add('hidden');
                    sheetCustom.classList.remove('hidden');
                    sheetCustom.focus();
                }
            });
        }
    }
    
    // 切换工作表输入方式
    function toggleSheetInput(showCustom = false) {
        const sheetSelect = document.getElementById('sheetName');
        const sheetCustom = document.getElementById('sheetNameCustom');
        
        if (sheetSelect && sheetCustom) {
            if (showCustom) {
                sheetSelect.classList.add('hidden');
                sheetCustom.classList.remove('hidden');
            } else {
                sheetSelect.classList.remove('hidden');
                sheetCustom.classList.add('hidden');
            }
        }
    }
</script>